package org.infodavid.common.persistence;

import java.util.Locale;

import javax.persistence.PersistenceException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.infodavid.common.model.ITemplate;
import org.infodavid.common.persistence.impl.AbstractDataService;
import org.infodavid.common.reflect.InstantiationHelper;

/**
 * The Class TemplateDataService.
 */
public abstract class TemplateDataService extends AbstractDataService<ITemplate,Long> {

  /** The singleton. */
  private static final TemplateDataService SINGLETON;

  /** The Constant log. */
  private static final Log LOGGER = LogFactory.getLog(TemplateDataService.class);

  static {
    try {
      SINGLETON = InstantiationHelper.getInstance().newInstance(TemplateDataService.class);
    }
    catch (final Exception e) {
      LOGGER.fatal("Can not instantiate the " + TemplateDataService.class.getName(), e);

      throw new Error(e);
    }
  }

  /**
   * returns the singleton.
   * @return the singletons
   */
  public static TemplateDataService getInstance() {
    return SINGLETON;
  }

  /**
   * Instantiates a new service.
   */
  protected TemplateDataService() {
    super();
  }

  /**
   * Find by name.
   * @param session the session
   * @param value the value
   * @param language the language
   * @return the template
   * @throws PersistenceException the persistence exception
   */
  public abstract ITemplate findByName(PersistenceSession session, String value, Locale language)
      throws PersistenceException;
}
